package com.systop.payment.controller;

import java.util.Arrays;
import java.util.Map;

import com.systop.common.exception.BizCodeEnum;
import com.systop.common.utils.PageCheck;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.systop.payment.entity.ClassifyEntity;
import com.systop.payment.service.ClassifyService;
import com.systop.common.utils.PageUtils;
import com.systop.common.utils.R;



/**
 * 
 *
 * @author jsj
 * @email jsj@gmail.com
 * @date 2022-05-05 11:46:06
 */
@RestController
@RequestMapping("payment/classify")
public class ClassifyController {
    @Autowired
    private ClassifyService classifyService;

    /**
     * 列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @Operation(summary = "查询所有分类")
    //@RequiresPermissions("payment:classify:list")
    public R list(@RequestParam Map<String, Object> params){

        PageUtils page = classifyService.queryPage(params);

        Map<String, Object> resultMap = PageCheck.pageCheck(params, page);

        if(!resultMap.get("page").equals(page.getCurrPage())){
            //当前页与上次访问页不同
            page = classifyService.queryPage(resultMap);
        }

        if(page.getCurrPage()>1&&page.getList().size()==0){
            return R.error(BizCodeEnum.INVALID_QUERY.getCode(),BizCodeEnum.INVALID_QUERY.getMsg());
        }

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("payment:classify:info")
    public R info(@PathVariable("id") Integer id){
		ClassifyEntity classify = classifyService.getById(id);

        return R.ok().put("classify", classify);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("payment:classify:save")
    public R save(@RequestBody ClassifyEntity classify){
		classifyService.save(classify);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("payment:classify:update")
    public R update(@RequestBody ClassifyEntity classify){
		classifyService.updateById(classify);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("payment:classify:delete")
    public R delete(@RequestBody Integer[] ids){
		classifyService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
